<?php

declare (strict_types=1);
namespace App\Model;

use App\Lib\Enum\FileConstant;
use function Hyperf\Support\env;

/**
 * @property int $id 
 * @property string $path 
 * @property string $type 
 * @property string $name 
 * @property string $extension 
 * @property int $size 
 * @property string $md5 
 * @property string $create_time 
 * @property string $update_time 
 * @property string $delete_time 
 */
class LinFile extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'lin_file';
    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = [];
    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'size' => 'integer'];

    protected array $appends = ['url'];


    public function getUrlAttribute():?string
    {
        if($this->type == FileConstant::LOCAL){
            $host = env('DOMAIN');
        }else{
            $host = env('IMG_DOMAIN');
        }
        return $host.env('FILE_STORE_DIR').'/'.$this->path;
    }
}